package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;


public class CSVDeclarationDTO extends java.lang.Object implements IsSerializable, ICSVDTO {


    // Fields    
     
     private long id;
     private String group;
     private String subgroupType;
     private String subject;
//     private Long subgroupsAmount;
     private Integer duration;
     private Integer alreadyScheduled;

     

     
     private boolean highlighted;

     public static final int SORT_CONST__SUBJECT = 0;
     public static final int SORT_CONST__SUBGROUP_TYPE = 1;
//     public static final int SORT_CONST__SUBGROUPS_AMOUNT = 3;
     public static final int SORT_CONST__DURATION = 2;
     public static final int SORT_CONST__ALREADY_SCHEDULED = 3;
     public static final int SORT_CONST__GROUP = 4;

     public static final int SORT_CONST__ID = 5;

	public CSVDeclarationDTO(long id, String group, String subgroupType,
			String subject, Long subgroupsAmount, Integer duration) {
		super();
		this.id = id;
		this.group = group;
		this.subgroupType = subgroupType;
		this.subject = subject;
//		this.subgroupsAmount = subgroupsAmount;
		this.duration = duration;
		this.alreadyScheduled = new Integer(0);
	}


	/** default constructor */
    public CSVDeclarationDTO() {
    }


	public String toString() {
		String result = "" +
			"[ " + CSVDeclarationDTO.class + "]" +
			"id: " + id +
			", groupID: " + group +
			", subgroupTypeID: " + subgroupType +
			", subjectID: " + subject +
			", subgroupsAmountID: " + subgroupType +
			", duration: " + duration; 
		return result;
	}

	
	

	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}


	public String getGroup() {
		return group;
	}


	public void setGroup(String group) {
		this.group = group;
	}


	public String getSubgroupType() {
		return subgroupType;
	}


	public void setSubgroupType(String subgroupType) {
		this.subgroupType = subgroupType;
	}


	public String getSubject() {
		return subject;
	}


	public void setSubject(String subject) {
		this.subject = subject;
	}


	

//	public Long getSubgroupsAmount() {
//		return subgroupsAmount;
//	}
//
//
//	public void setSubgroupsAmount(Long subgroupsAmount) {
//		this.subgroupsAmount = subgroupsAmount;
//	}


	public Integer getDuration() {
		return duration;
	}


	public void setDuration(Integer duration) {
		this.duration = duration;
	}


	public boolean isHighlighted() {
		return highlighted;
	}


	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}


	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__SUBJECT) {
			return "" + getSubject();
		} else if (col == SORT_CONST__DURATION) {
			return "" + getDuration();
		} else if (col == SORT_CONST__GROUP) {
			return "" + getGroup();
		} else if (col == SORT_CONST__SUBGROUP_TYPE) {
			return "" + getSubgroupType();
//		} else if (col == SORT_CONST__SUBGROUPS_AMOUNT) {
//			return "" + getSubgroupsAmount();
		} else if (col == SORT_CONST__ALREADY_SCHEDULED) {
			return "" + getAlreadyScheduled();
		}
		return "no field";
	}

	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVDeclarationDTO obj1;
			    CSVDeclarationDTO obj2;
			    if (o1 instanceof CSVDeclarationDTO && o2 instanceof CSVDeclarationDTO) {

					obj1 = (CSVDeclarationDTO) o1;
					obj2 = (CSVDeclarationDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__SUBJECT) {
						return obj1.getSubject().compareTo(obj2.getSubject());
					} else if (colIndex == SORT_CONST__DURATION) {
						return obj1.getDuration().compareTo(obj2.getDuration());
					} else if (colIndex == SORT_CONST__GROUP) {
						return obj1.getGroup().compareTo(obj2.getGroup());
					} else if (colIndex == SORT_CONST__SUBGROUP_TYPE) {
						return obj1.getSubgroupType().compareTo(obj2.getSubgroupType());
//					} else if (colIndex == SORT_CONST__SUBGROUPS_AMOUNT) {
//						return obj1.getSubgroupsAmount().compareTo(obj2.getSubgroupsAmount());
					} else if (colIndex == SORT_CONST__ALREADY_SCHEDULED) {
						return obj1.getAlreadyScheduled().compareTo(obj2.getAlreadyScheduled());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}


	public Integer getAlreadyScheduled() {
		return alreadyScheduled;
	}


	public void setAlreadyScheduled(Integer alreadyScheduled) {
		this.alreadyScheduled = alreadyScheduled;
	}






}